package com.anzia.file;

import java.io.File;

/**
 *@ClassName ListDemo
 *@Description
 *@Author Anzia.
 *@Date 2021/4/9 19:49
 *@Version 1.0
 **/
public class ListDemo {
    public static void main(String[] args) {
        //listDir(new File("D:\\docunment_save\\qq_docunment"));
        deleteDir(new File("D:\\SteamLibrary - 副本"));
    }

    //递归遍历文件夹
    public static void listDir(File dir) {
        File[] files = dir.listFiles();
        if (files != null && files.length > 0) {
            for (File file : files) {
                if (file.isDirectory()) {
                    listDir(file); //递归
                } else {
                    System.out.println(file);
                }
            }
        }
    }

    //递归删除文件夹
    public static void deleteDir(File dir) {
        File[] files = dir.listFiles();
        if (files != null && files.length > 0) {
            for (File file : files) {
                if (file.isDirectory()) {
                    deleteDir(file);
                } else {
                    System.out.println(file + "删除成功！");
                    file.delete();
                }
            }
        }
        System.out.println(dir.getName() + dir.delete());
    }
}
